<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ taglib prefix ="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<%@ include file="/common/common-css.v2.jsp" %>
		<style>
		#jquery-table td{word-break: break-all;word-wrap: break-word;}
		.load_bg{background:#000;opacity:0.1;left:0px;top:0px;position:fixed;height:100%;width:100%;overflow:hidden;z-index:10000;}
		.load_img{left:50%;top:180px;position:fixed;height:50px;overflow:hidden;z-index:20000;}
		.modal{
			z-index: 9;
		}
		.modal-backdrop{
			z-index: 8;
		}
		#jquery-table .btn-sm{
			margin-right: 10px;
		}
		.discovery-alert {
		  position: fixed;
		  left: 10%;
		  top: 300px;
		  display: none;
		}
		.glyphicon{
			cursor: pointer;
		}
		.finalListContent{
			word-wrap: break-word;
			word-break: break-all;
			padding: 0 20px;
		}
		#finalListContentModal .modal-dialog{
			width: 65%;
		}
		</style>
	</head>
<body class="no-skin" style="min-height: 1000px;">
<div  class="load_bg" style="display:none;" ></div>
<img src="http://img.xmiles.cn/commentloading.gif" class="load_img" style="display:none"/>
<div class="page-content">
<div id="test"></div>
			<div class="page-header" style="margin-bottom:0px;padding-bottom:10px;">
			
				<h1 id="fu_name">
					
				</h1>
			</div>
	<form id="queryForm" >
	<div class="page-content-area">
		<div class="row">
			<div class="col-sm-12">
				<div class="widget-box" style="border:0px solid #ccc; border-top:none;border-bottom:none;">
					<div class="widget-header widget-header-blue widget-header-flat">
						<h4 class="widget-title">选择条件进行查询</h4>

						<div class="widget-toolbar">
							<a href="#" data-action="collapse">
								<i class="ace-icon fa fa-chevron-up"></i>
							</a>
						</div>
					</div>

					<div class=" widget-body">
						<!-- <div class="widget-main" style="padding:12px;border:0px solid #ccc; border-top:none;border-bottom:none;"> -->
									<div class="widget-main clearfix" >
										
										<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
											<label class="col-sm-5 control-label" for="infotype" style="text-align:right;">渠道:</label>
											<div class="col-sm-7">
												<s:select name="channel" list="%{paramsMap.channelList}" listKey="code" listValue="name" headerKey="" headerValue="--请选择--" cssClass="form-control" value=""></s:select>
											</div>
										</div>

										<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
											<label class="col-sm-5 control-label" for="platform" style="text-align:right;">版本:</label>
											<div class="col-sm-7">
												<select class="form-control" name="platform" id="platform">
													<option value="1">安卓</option>
													<option value="2">ios</option>
												</select>
											</div>
										</div>
										
										<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
											<label class="col-sm-5 control-label" for="status" style="text-align:right;">状态:</label>
											<div class="col-sm-7">
												<select class="form-control" name="status" id="status">
													<option value="">不限</option>
													<option value="1" selected>上线</option>
													<option value="0">下线</option>
												</select>
											</div>
										</div>
										
										<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
											<label class="col-sm-5 control-label" for="type" style="text-align:right;">类型:</label>
											<div class="col-sm-7">
												<select class="form-control" name="type" id="type">
													<option value="">不限</option>
													<option value="0">滚动banner（默认）</option>
													<option value="1">1*1 文字图片豆腐块</option>
													<option value="2">2*1 豆腐块</option>
													<option value="3">1*1 图片豆腐块</option>
													<option value="4">下方3个豆腐块</option>
													<option value="5">启动页捆绑下载</option>
												</select>
											</div>
										</div>

										
							</div><!-- /.widget-main -->
					</div><!-- /.widget-body -->
				</div><!-- /.widget-box -->
			</div><!-- /.col-sm-12 -->
				<div class="col-md-12 center">
				<div class="clearfix form-actions">
				
					<button class="btn btn-purple  no-border" type="button" name="btn-query" onclick="query_any()" id="btn-query">
						<i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
						查询
					</button>
					&nbsp;&nbsp;&nbsp;
					<button class="btn btn-grey  no-border" type="reset">
						<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
						重置
					</button>
					&nbsp;&nbsp;&nbsp;
					<button class="btn btn-primary no-border" type="button" id="btn-add">
						<i class="ace-icon fa fa-plus icon-on-right bigger-110"></i>
						新增
					</button>
					&nbsp;&nbsp;&nbsp;
					<button class="btn btn-primary no-border" type="button" id="btn-create">
						<i class="ace-icon fa fa-exchange icon-on-right bigger-110"></i>
						生成
					</button>
					<h1 style="color:#d15b47">内容变化后必须重新生成数据</h1>
				  </div>
		   </div>
		</div><!-- /.row -->
		
		<div class="row">
			<div class="col-xs-12">
				<table id="jquery-table" class="table table-striped table-bordered table-hover">
				
				</table>
			</div><!-- /.col -->
		</div><!-- /.row -->
			
	</div><!-- /.page-content-area -->
	</form>
</div><!-- /.page-content -->

<!--模态框-->
<div class="modal fade" id="Modal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">新增</h4>
      </div>
      <div class="modal-body clearfix modal-content">
      	
      	<form id="myForm">
      	    <input type="hidden" name="id" id="idForEdit" />
      		<div class="form-group col-xs-12 col-md-6 col-lg-6">
				<label class="col-sm-4 control-label text-right" for="schannel">渠道:</label>
				<div class="col-sm-8">
					<s:select id="schannel" name="schannel" list="%{paramsMap.channelList}" listKey="code" listValue="name" cssClass="form-control" value="9999"></s:select>
				</div>
			</div>
			
			<div class="form-group col-xs-12 col-md-6 col-lg-6">
				<label class="col-sm-4 control-label text-right" for="splatform">版本:</label>
				<div class="col-sm-8">
					<select class="form-control" name="splatform" id="splatform">
						<option value="1">安卓</option>
						<option value="2">ios</option>
					</select>
				</div>
			</div>
			
			<div class="form-group col-xs-12 col-md-6 col-lg-6">
				<label class="col-sm-4 control-label text-right" for="stype">类型:</label>
				<div class="col-sm-8">
					<select class="form-control" name="stype" id="stype">
						<option value="0">滚动banner（默认）</option>
						<option value="1">1*1 文字图片豆腐块</option>
						<option value="2">2*1 豆腐块</option>
						<option value="3">1*1 图片豆腐块</option>
						<option value="4">下方3个豆腐块</option>
						<option value="5">启动页捆绑下载</option>
					</select>
				</div>
			</div>
      	
    		<div class="form-group col-xs-12 col-md-6 col-lg-6">
				<label class="col-sm-4 control-label text-right" for="spkgname">包名:</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="spkgname" id="spkgname" />
				</div>
			</div>

			<div class="form-group col-xs-12 col-md-6 col-lg-6">
				<label class="col-sm-4 control-label text-right" for="sstitle">包标题:</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="sstitle" />
				</div>
			</div>

			<div class="form-group col-xs-12 col-md-6 col-lg-6">
				<label class="col-sm-4 control-label text-left" for="slink">包地址:</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="slink" />
				</div>
			</div>
			
			<div class="form-group col-xs-12 col-md-6 col-lg-6">
				<label class="col-sm-4 control-label text-right" for="simgurl">图片:</label>
				<div class="col-sm-8">
					<input type="hidden" name="simgurl" id="simgurl" />
					<button class="btn btn-sm btn-primary btn-upload">
						上传
					</button>
					&nbsp;&nbsp;&nbsp;
					<img id="simgsrc" style="width: 75px; display: inline-block;" />
				</div>
			</div>
			
			<div class="form-group col-xs-12 col-md-6 col-lg-6">
				<label class="col-sm-4 control-label text-right" for="spkgname">结束时间:</label>
				<div class="col-sm-8">
					<input class="form-control date-time-picker" type="text" name="send_time" id="send_time" data-date-format="yyyy-mm-dd hh:ii:ss" />
				</div>
			</div>
			
			<!--真实提交的跳转参数-->
			<input type="hidden" name="launch_params" id="launch_params" />
			
			<div class="form-group col-xs-12 col-md-6 col-lg-6">
				<label class="col-sm-4 control-label text-right" for="stitle">跳转标题:</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="stitle" />
				</div>
			</div>
			
			<div class="form-group col-xs-12 col-md-12 col-lg-12">
				<label class="col-sm-2 control-label text-right" for="scontent">内容:</label>
				<div class="col-sm-10">
					<input class="form-control" type="text" id="scontent" name="scontent" style="margin-left: -3px;" />
				</div>
			</div>
			
			
		</form>	
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	    <button type="button" class="btn btn-primary" id="confirm">确认</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!--模态框-->
<div class="modal fade" id="uploadModal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">上传图片</h4>
      </div>
      <div class="modal-body clearfix">
	    <form id="addImage" method="post" enctype="multipart/form-data" >
			<div class="row">
				<div class="form-group col-xs-12">
					<div class="input-group col-sm-12">
						<input type="file" class="form-control" name="myFile" accept=".png,.jpg,.jpeg" />
					</div>
				</div>
			</div>		
        </form>			
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	    <button type="button" class="btn btn-primary" disabled id="upload">上传</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!--模态框-->
<div class="modal fade" id="finalListContentModal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">请自行复制使用</h4>
      </div>
      <div class="modal-body clearfix">
	    <div class="row finalListContent"></div>		
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<div class="alert alert-danger alert-dismissible discovery-alert discovery-up" role="alert">
  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  <strong>注意!</strong> 第一条不能再上移了.
</div>
<div class="alert alert-danger alert-dismissible discovery-alert discovery-down" role="alert">
  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  <strong>注意!</strong> 最后一条不能再下移了.
</div>

<%@ include file="/common/common-js.jsp" %>
<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery.form.js"></script>
<!-- inline scripts related to this page -->
<script type="text/javascript">

var lastAaData = null;
var uploadModalTop = 100;

function getUrlParam(url,name){
    var pattern = new RegExp("[?&]" + name +"\=([^&]+)","g");
    var matcher = pattern.exec(url);
    var items = null;
    if(matcher != null){
        try{
            items = decodeURIComponent(decodeURIComponent(matcher[1]));   
        }catch(e){
            try{
                items = decodeURIComponent(matcher[1]);
            }catch(e){
                items = matcher[1];
            }
        }
    }
    return items;
}

//【查询】按钮Click事件
function query_any(){
	$(".load_bg,.load_img").show();
	if(jqTable != null){
		jqTable.fnDraw();
		
	}else{
		loaddata();	
	}
};

//时间控件
jQuery(function($) {
	$('.date-time-picker').datetimepicker({
		autoclose:true,
		format: 'yyyy-mm-dd hh:ii:ss'
	});
	
	//初始化执行请求
	query_any();
	
	$('#btn-add').on('click', function(){
		
		//清空值
		$('#idForEdit').val('');
		$('#schannel option[value=9999]').prop('selected', true);
		$('#splatform option[value=1]').prop('selected', true);
		$('#stype option[value=1]').prop('selected', true);
		$('#launch_params').val('');
		$('#spkgname').val('');
		$('#sstitle').val('');
		$('#scontent').val('');
		$('#slink').val('');
		$('#stitle').val('');
		$('#send_time').val('');
		$('#simgurl').val('');
		$('#simgsrc').attr('src', '');
		$('#confirm').attr('data-type', 1);
		$('#Modal').css("top", 100).modal('show');
		
		uploadModalTop = 100;
		
		return false;
	});
	
	//确认事件
	$('#confirm').on('click', function(){
		//type为1,新增;2修改
		var type = $(this).attr('data-type');
		var action = "";
		if(type == 1){
			action = ctx + "/homebanner/addApp.action";
		}else if(type == 2){
			action = ctx + "/homebanner/updateApp.action?type=1";
			$('#idForEdit').val($(this).attr('data-id'));
		}
		if($('#simgsrc').attr('src') == '' || $('#simgsrc').attr('src') == null){
			alert('请上传图片');
		}else{
		    //生成htmlUrl
		    var htmlUrl = '';
		    if($('#splatform').val() == 1){
		    	htmlUrl = 'http://xmiles.cn/download_page/index.html?durl=' + $('#slink').val() + '&name=' + $('#sstitle').val() + '&pkg=' + $('#spkgname').val();
		    }else if($('#splatform').val() == 2){
		    	htmlUrl = $('#slink').val();
		    }
			//生成launch_params
			var launchParamsJson = {
				"launch":"launch_vc_webView",
				"launchParams":{"title":$('#stitle').val(),
					"htmlUrl":htmlUrl,
					"withHead":"0",
					"showToolbar":"0",
					"clearTop":"0",
					"canBlockNetworkImg":"0",
					"reloadWhenLogin":"0",
					"takeOverBackPressed":"0",
					"callbackWhenResumeAndPause":"0",
					"showTitle":"1",
					"injectCss":"0"
				}
			};
			console.log(JSON.stringify(launchParamsJson));
		    $('#launch_params').val(JSON.stringify(launchParamsJson));
		    saveForm('#myForm', action, '#Modal', false);
		}
	});
	
	$('#status').on('change', function(){
		query_any();
		if($(this).val() == 1){
			$('#btn-create').removeClass('hidden');
		}else{
			$('#btn-create').addClass('hidden');
		}
	})
	
	$('.btn-upload').on('click', function(){
		$('#Modal').modal('hide');
		$('#uploadModal').css("top", uploadModalTop).modal('show');
		return false;
	});
	
	$('input[name="myFile"]').on('change', function(){
		if($(this).val() != ''){
			$('#upload').prop('disabled', false);
		}else{
			$('#upload').prop('disabled', true);
		};
	});
	
	$('#upload').on('click', function(){
		saveForm('#addImage', '${ctx}/mall/fileupload/fileUpload.action', '#uploadModal', true);
		return false;
	});
	
	//上移
    $('#jquery-table').delegate('.glyphicon-chevron-up','click',function(){
		var arr = new Array();
		var thispos=$(this).parent('td').parent('tr');
		var thishtml=thispos.clone();
		var prevpos=$(this).parent('td').parent('tr').prev();
		var thisindex = thispos.index();
		if(thisindex==0){
			$('.discovery-up').show();
			setTimeout("$('.discovery-up').hide()",3000);
		}else{

			thispos.remove();
			prevpos.before(thishtml);
			$('#jquery-table tbody tr').each(function(){
				arr.push($(this).find('td:nth-child(1)').find('.glyphicon-chevron-up').attr('data-tabindex'));
			});
			var arrstring = arr.join("#");
			console.log(arrstring);
			$.ajax({
				url: ctx+'/homebanner/sortApp.action',
				type: 'POST',
				dataType: 'json',
				data: {"sortlist": arrstring},
				success:function(data){
                    console.log(data);
				},
				error:function(){
					console.log('排序失败');
				}
			});
			

		}
	});
    //下移
	$('#jquery-table').delegate('.glyphicon-chevron-down','click',function(){
		var arr = new Array();
		var thispos=$(this).parent('td').parent('tr');
		var thishtml=thispos.clone();
		var nextpos=$(this).parent('td').parent('tr').next();
		var thisindex = thispos.index();
		if(thisindex==$("#jquery-table tbody tr").length - 1){
			$('.discovery-down').show();
			setTimeout("$('.discovery-down').hide()",3000);
		}else{
            thispos.remove();
	        nextpos.after(thishtml);
			$('#jquery-table tbody tr').each(function(){
				arr.push($(this).find('td:nth-child(1)').find('.glyphicon-chevron-up').attr('data-tabindex'));
			});
			var arrstring = arr.join("#");
			$.ajax({
				url: ctx + '/homebanner/sortApp.action',
				type: 'POST',
				dataType: 'json',
				data: {"sortlist": arrstring},
				success:function(data){
                    console.log(data);
				},
				error:function(){
					console.log('排序失败');
				}
			});
			
		}
	});
	
	//修改按钮点击事件
	$(document).delegate('.btn-edit', 'click', function(){
		$('#schannel option[value=' + $(this).attr('data-channel') + ']').prop('selected', true);
		$('#splatform option[value=' + $(this).attr('data-platform') + ']').prop('selected', true);
		$('#launch_params').val($(this).attr('data-launch_params'));
		var thislaunchParamsJSON = JSON.parse($(this).attr('data-launch_params'));
		$('#spkgname').val(getUrlParam(thislaunchParamsJSON.launchParams.htmlUrl, "pkg"));
		$('#sstitle').val(getUrlParam(thislaunchParamsJSON.launchParams.htmlUrl, "name"));
		$('#slink').val(getUrlParam(thislaunchParamsJSON.launchParams.htmlUrl, "durl"));
		$('#stitle').val(thislaunchParamsJSON.launchParams.title);
		$('#scontent').val($(this).attr('data-content'));
		$('#send_time').val($(this).attr('data-end_time'));
		$('#simgurl').val($(this).attr('data-imgurl'));
		$('#simgsrc').attr('src', $(this).attr('data-imgurl'));
		//显示模态框
		$('#confirm').attr({
			"data-type": 2,
		    "data-id": $(this).attr('data-id')
		});
		var thisTop = $(this).position().top;
		uploadModalTop = thisTop;
		$('#Modal').css("top", thisTop - 300).modal('show');
		return false;
	});
	
	//上下线
	$(document).delegate('.btn-oline', 'click', function(){
		var id = $(this).attr('data-id');
		var status = 1;
		//上线 
		if(!$(this).hasClass('btn-goonline')){
			status = 0;
		};
		$.ajax({
			"type": "POST",
			"dataType": 'json',
			"url": ctx + "/homebanner/updateApp.action?type=2",
			"data":{"status": status, "id": id},
			"beforeSend": function(){
				$(".load_bg,.load_img").show();
			},
			"success": function(resp){
                console.log(resp);	
                query_any();
			},
			"error": function(XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus);
			},
			"complete": function(){
				$(".load_bg,.load_img").hide();
			}
		});
		
	});
	
	//直接删除
	$(document).delegate('.btn-delete', 'click', function(){
		var id = $(this).attr('data-id');
		$.ajax({
			"type": "POST",
			"dataType": 'json',
			"url": ctx + "/homebanner/deleteApp.action",
			"data":{"id": id},
			"beforeSend": function(){
				$(".load_bg,.load_img").show();
			},
			"success": function(resp){
                console.log(resp);	
                query_any();
			},
			"error": function(XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus);
			},
			"complete": function(){
				$(".load_bg,.load_img").hide();
			}
		});
		
	});
	
	//生成最终的json--要判断是否"启动页捆绑下载.如果是,launch_params里面仅需要包地址"
	$('#btn-create').on('click', function(){
		var stypeVal = $('#type').val();
		var finalList = [];
		$.each(lastAaData, function(index, item){
			var thisObject = new Object();
			thisObject.pkgname = item.pkgname;
			thisObject.content = item.content;
			thisObject.imgurl = item.imgurl;
			thisObject.id = item.id;
			thisObject.end_time = getTimeStamp(item.end_time);
			if(stypeVal == 5){
				var thisLaunchParams = JSON.parse(item.launch_params);
				var thisHtmlUrl = thisLaunchParams.launchParams.htmlUrl;
				thisDUrl = GetQueryString("durl", encodeURI(thisHtmlUrl));
				thisObject.launch_params = thisDUrl;
			}else{
				thisObject.launch_params = item.launch_params;
			}
			thisObject.name = JSON.parse(item.launch_params).launchParams.title;
			finalList.push(thisObject);
		});
		
		$('.finalListContent').html(JSON.stringify(finalList).toString());
		$('#finalListContentModal').modal('show');
	});

});

function getTimeStamp(timeString){
	timeString = timeString.replace(/-/g,"/");
	var date = new Date(timeString);
	return date.getTime();
}

//表单异步提交
function saveForm(form, action, thisModal, closeUploadModal){
	var options = { 
		url : action,
		type : "POST",
		dataType : "json",
		beforeSend: function(){
			$(".load_bg,.load_img").show();
		},
		success : function(data) {
		    console.log(JSON.stringify(data));
		    $(thisModal).modal('hide');
		    if(closeUploadModal){
		    	$('#simgurl').val(data);
		    	$('#simgsrc').attr('src', data);
		    	$('#Modal').modal('show');
		    }else{
		    	query_any();
		    };
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
		    alert(textStatus);
		    console.log(XMLHttpRequest, textStatus, errorThrown);
		},
        complete : function(){
			$(".load_bg,.load_img").hide();
		}
	};
    $(form).ajaxSubmit(options);
};
          
var jqTable = null;
var loaddata = function(){
	jQuery(function($) {
		jqTable = $('#jquery-table').dataTable( {
		    //数据列控制（包括对应返回JSON属性名称，对应表头列索引位置、数据转换封装等）
		    "columnDefs": [
		    	{	  
					  "title":'排序',
					  "targets": [0],
					  "data": "",   //JSON返回属性
					  "width": "10px",
					  "bSortable": false,
					  "class": "center",
					  "render": function(value, type, row) { // 返回自定义内容
						  return '<i class="glyphicon glyphiconfir glyphicon-chevron-up" data-tabindex="'+row.id+'" data-ordernum="'+row.seqence+'"></i><br><i class="glyphicon glyphicon-chevron-down"></i>';
					  } 
				},
		    	{	  
		    		  "title":"名称",
		    	  	  "targets": [1],
					  "data": "launch_params",   //JSON返回属性
		    	  	  "class": "center",
		    	  	  "bSortable": false,
					  "width": "50px",
					  "render": function(value, type, row) { // 返回自定义内容
					  	   var thislaunchParamsJSON = JSON.parse(value);
					  	   return getUrlParam(thislaunchParamsJSON.launchParams.htmlUrl, "name");  
					  }
		    	},
		    	{	  
		    		  "title":'跳转标题',
		    	  	  "targets": [2],
					  "data": "launch_params",   //JSON返回属性
		    	  	  "class": "center",
		    	  	  "bSortable": false,
					  "width": "50px",
					  "render": function(value, type, row) { // 返回自定义内容
					  	   var thislaunchParamsJSON = JSON.parse(value);
					  	   return thislaunchParamsJSON.launchParams.title;  
					  }
		    	},
		    	{
		    		  "title":'图片',
		    	  	  "targets": [3],
					  "data": "imgurl",   //JSON返回属性
		    	  	  "class": "center",
		    	  	  "bSortable": false,
					  "width": "100px",
					  "render": function(value, type, row) { // 返回自定义内容
					  	   return '<img style="width:100px;" src="' + value + '"/>';  
					  }
		    	},
		    	{	  
		    		  "title":"包名",
		    	  	  "targets": [4],
					  "data": "pkgname",   //JSON返回属性
		    	  	  "class": "center",
		    	  	  "bSortable": false,
					  "width": "50px"
		    	},
		    	{	  
		    		  "title":"包地址",
		    	  	  "targets": [5],
					  "data": "launch_params",   //JSON返回属性
		    	  	  "class": "center",
		    	  	  "bSortable": false,
					  "width": "50px",
					  "render": function(value, type, row) { // 返回自定义内容
					  	   var thislaunchParamsJSON = JSON.parse(value);
					  	   if($('#platform').val() == 1){
					  	   		return '<a style="width:250px;display:block;word-wrap:break-word;word-break:break-all;overflow:auto;margin:0 auto;" href="' + getUrlParam(thislaunchParamsJSON.launchParams.htmlUrl, "durl") + '" target="_blank">' + getUrlParam(thislaunchParamsJSON.launchParams.htmlUrl, "durl") + '</a>';  
					  	   }else{
					  	   	    return '<a style="width:250px;display:block;word-wrap:break-word;word-break:break-all;overflow:auto;margin:0 auto;" href="' + thislaunchParamsJSON.launchParams.htmlUrl + '" target="_blank">' + thislaunchParamsJSON.launchParams.htmlUrl + '</a>'; 
					  	   }
					  }
		    	},
		    	{
		    		  "title":"内容",
		    	  	  "targets": [6],
					  "data": "content",   //JSON返回属性
		    	  	  "class": "center",
		    	  	  "bSortable": false,
					  "width": "50px"
		    	},
		    	{
		    		  "title":"下线时间",
		    	  	  "targets": [7],
					  "data": "end_time",   //JSON返回属性
		    	  	  "class": "center",
		    	  	  "bSortable": false,
					  "width": "50px"
		    	},
		    	{	  
		    		  "title":'操作',
		    	  	  "targets": [8],
					  "data": "status",   //JSON返回属性
		    	  	  "class": "center",
		    	  	  "bSortable": false,
					  "width": "100px",
					  "render": function(value, type, row) { // 返回自定义内容
					  	   var onOrOffLineBtn = '';
					  	   if(value == 0){
					  	   	   onOrOffLineBtn = '<a class="btn btn-sm btn-success btn-oline btn-goonline" data-id="' + row.id + '">上线</a>';
					  	   }else if(value == 1){
					  	   	   onOrOffLineBtn = '<a class="btn btn-sm btn-danger btn-oline btn-gooffline" data-id="' + row.id + '">下线</a>';
					  	   }
					  	   return '<a class="btn btn-sm btn-primary btn-edit" data-id="' + row.id + '" data-imgurl="' + row.imgurl + '" data-end_time="' + row.end_time + '" data-channel="' + row.channel + '" data-content="' + row.content + '" data-platform="' + row.platform + '" data-launch_params=' + row.launch_params + '>编辑</a>'
					  	         + onOrOffLineBtn
					  	         + '<a class="btn btn-sm btn-danger btn-delete" data-id="' + row.id + '">删除</a>';
					  }
		    	}

		  	],
			"sAjaxSource": ctx + "/homebanner/listApp.action",//数据源URL
			"fnServerData": function ( sSource, aoData, fnCallback ) {//从服务器请求数据
		   			var data = $('#queryForm').serializeObject();
					data.aoData = JSON.stringify(aoData);
					$.ajax({
						"type": "POST",
						"dataType": 'json',
						"url": sSource,
						"data":data,
						"success": function(resp){
                            console.log(resp);
                            lastAaData = resp.aaData;
							fnCallback(resp);
							initListPage();
						},
						"error": function(XMLHttpRequest, textStatus, errorThrown) {
                            alert(textStatus);
						},
						"complete": function(){
							$(".load_bg,.load_img").hide();
						}
					});
			},
			"sScrollXInner": "100%",
			"sScrollY": "100%",//如果不设置，IE会有问题
			"aLengthMenu": [100],
		    "aaSorting": [[1,"asc"]] //初始化加载，默认按第几列排序、排序方式（列从0开始计算）
		});
	});
};

//获取链接参数的方法
function GetQueryString(name, $url){  
   var url = decodeURI($url);
   var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");  
   var matcher = pattern.exec(url);  
   var items = null;  
   if(null != matcher){  
     try{  
         items = decodeURIComponent(decodeURIComponent(matcher[1]));  
     }catch(e){  
         try{  
            items = decodeURIComponent(matcher[1]);  
         }catch(e){  
            items = matcher[1];  
         }  
     }  
   }  
   return items;  
};


</script>
		
</body>
</html>